package com.study.controller;

import com.study.pojo.Clazz;
import com.study.pojo.PageResult;
import com.study.pojo.Result;
import com.study.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    ClazzService clazzService;
    @GetMapping
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult<Clazz> pageResult = clazzService.page(page, pageSize);
        return Result.success(pageResult);
    }
    @DeleteMapping
    public Result delete(Integer id){
        clazzService.deleteById(id);
        return Result.success();
    }
    @PostMapping
    public Result insert(@RequestBody Clazz clazz){
        log.info("添加的班级是："+clazz);
        clazzService.insert(clazz);
        return Result.success();
    }

}
